package simpleGui;

import java.awt.event.MouseEvent;

import processing.core.PApplet;
import processing.core.PGraphics;

public class GuiSlider extends GuiComponent {
	float value=0.5f;
	GuiSlider(Gui gui,int x,int y,int width,int height){
		super(gui,x,y,width,height);
	}
	public float getRelValue(){
		return value;
	}
	public void display(PGraphics g){
		g.pushStyle();
		g.stroke(200);
		g.fill(100);
		g.rectMode(PGraphics.CORNER);
		g.rect(x,y,w,h);
		g.noStroke();
		g.fill(255);
		g.rectMode(PGraphics.CENTER);
		g.rect(x+value*w,y+h*0.5f,5,h);
		
		g.popStyle();
	}
	public void setValue(int mx,int my){
		if (contains(mx,my)){
			value=((mx-x)*1f/w);
		}
	}
	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		super.mouseReleased(arg0);
		setValue(arg0.getX(),arg0.getY());
	}
	@Override
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub
		super.mouseDragged(arg0);
		setValue(arg0.getX(),arg0.getY());
	}
}
